package cn.tedu.sims.service.impl;

import cn.tedu.sims.ex.ServiceException;
import cn.tedu.sims.mapper.LogLoginMapper;
import cn.tedu.sims.pojo.vo.UserLogLoginListItemVO;
import cn.tedu.sims.service.UserLogLoginService;
import cn.tedu.sims.web.ServiceCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserLogLoginServiceImpl implements UserLogLoginService {
    @Autowired
    private LogLoginMapper logLoginMapper;

    @Override
    public List<UserLogLoginListItemVO> selectByUserName(String username) {
        return logLoginMapper.selectByUserName(username);
    }

    @Override
    public List<UserLogLoginListItemVO> list() {
        return logLoginMapper.list();
    }

    @Override
    public void delete(Long id) {
        int countById=logLoginMapper.contById(id);
        if (countById!=1){
            throw new ServiceException(ServiceCode.ERR_NOT_FOUND,"删除失败,日志不存在");
        }

        int row=logLoginMapper.delete(id);
        if (row!=1){
            throw new ServiceException(ServiceCode.ERR_DELETE,"删除失败,服务器繁忙");
        }
    }
}
